package org.carpediem.conman.entity;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Mark Petrovic
 */
@Entity
public class Contact extends DomainObject {
    public final static String CONTACT = "contact";

    private long id;
    private String emailAddress;
    private String firstName;
    private String lastName;
    private String address1;
    private String address2;
    private String city;
    private String state;
    private String zip;
    private String landLine;
    private String mobile;
    private String fax;
    private Set<Document> document = new HashSet<Document>();
    private Set<Note> note = new HashSet<Note>();
    private Set<TouchPoint> touchPoint = new HashSet<TouchPoint>();

    @Id
    @GeneratedValue
    public long getId() {
        return id;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Column(length = 32)
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(length = 64)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(length = 128)
    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address) {
        this.address1 = address;
    }

    @Column(length = 128)
    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address) {
        this.address2 = address;
    }

    @Column(length = 32)
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Column(length = 2)
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Column(length = 10)
    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    @OneToMany(cascade = CascadeType.ALL/*, fetch = FetchType.EAGER*/)
    public Set<Document> getDocument() {
        return document;
    }

    public void setDocument(Set<Document> document) {
        this.document = document;
    }

    @OneToMany(cascade = CascadeType.ALL/*, fetch = FetchType.EAGER*/)
    public Set<Note> getNote() {
        return note;
    }

    public void setNote(Set<Note> note) {
        this.note = note;
    }

//    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @OneToMany(cascade = CascadeType.ALL)
    public Set<TouchPoint> getTouchPoint() {
        return touchPoint;
    }

    public void setTouchPoint(Set<TouchPoint> touchPoint) {
        this.touchPoint = touchPoint;
    }

    public void addDocument(Document doc) {
        document.add(doc);
        doc.setContact(this);
    }

    public void add(Note aNote) {
        note.add(aNote);
        aNote.setContact(this);
    }

    public String toString() {
        return this.getClass().getName() + ":" + id + ":" + this.emailAddress;
    }

    public String getLandLine() {
        return landLine;
    }

    public void setLandLine(String landLine) {
        this.landLine = landLine;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

}
